import instance from "@/request/request";
import type { Res } from '@/request/ResultApi';

//获取所有产品
export const getAllProduct = (size: number, current: number, productName: String, productId: number, timeOrderBy: number): Res<null> => {
    let str=""
    if(productName!='')str+='&productName='+productName
    if(productId!=-1&&!Number.isNaN(productId))str+='&productId='+productId
    return instance.get(`/product/all?size=${size}&current=${current}&timeOrderBy=${timeOrderBy}${str}`);
}

//添加产品
export const addProduct = (data: {
    name: String,
    type: String,
    description: String
}): Res<null> => instance.post("/product/add", data);

//修改产品
export const updateProduct = (data: {
    productId: String,
    name: String,
    type: String,
    description: String
}): Res<null> => instance.post("/product/update", data);

//删除产品
export const removeProduct = (productId: number): Res<null> =>
    instance.post(`/product/delete?productId=${productId}`);

//批量删除产品
export const removeProducts = (data: []): Res<null> => instance.post("/product/deletes", data);